package paf.exporter;

import java.awt.Component;
import java.awt.Graphics2D;
import java.io.FileOutputStream;

import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfTemplate;
import com.itextpdf.text.pdf.PdfWriter;

public class PDFFile implements FileInterface {

	protected PDFFile() {}
	
	/**
	 * @see paf.exporter/FileInterface.java
	 */
	@Override
	public void writeToFile(Component c, String fileName) {
		Document document = new Document();
		try {
			PdfWriter writer;
			writer = PdfWriter.getInstance(document, new FileOutputStream(fileName + ".pdf"));
			document.open();
			PdfContentByte cb = writer.getDirectContent();
			PdfTemplate tp = cb.createTemplate(500, 500);
			Graphics2D g2 = tp.createGraphics(500,500);
			g2.scale(0.5, 0.5);
			c.print(g2);
			g2.dispose();
			cb.addTemplate(tp, 30, 300);
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}
		document.close();
	}
	
	@Override
	public String toString() {
		return "PDF File";
	}
}
